import React, { Component } from 'react';
import { HashRouter as Router,Route,Link,NavLink,Redirect,Switch} from 'react-router-dom';
import Action from './Action';
import Store from './Store';
import '../css/demo.css';
import '../css/iconfont.css';


import Home from './Home';
import Cart from './Cart';
import Classify from './Classify';
import Mycenter from './Mycenter';
import News from './News';
import Productlist from './Productlist';
import Setput from './Setput';
import Login from './Login';
import Detail from './Detail';
import Register from './Register';

function getCookie(name){
	var str = document.cookie;
	var arr = str.split("; ");
	for(var i = 0; i < arr.length; i++){
		var arr1 = arr[i].split("=");
		if(arr1[0]==name){
			return arr1[1];
		}
	}
}
function setCookie(name,val,n){
	var oDate = new Date();
	oDate.setDate(oDate.getDate()+n);
	document.cookie = name + "=" + val + ";expires="+ oDate ;
}
function removeCookie(name){
	setCookie(name,1,-1);
}
var token=getCookie('token')








class Demo extends React.Component{
	constructor(props){
		super(props)
	
	}
	wode(){
		if(token){
			window.location.href="#/mycenter"
		}else{
			window.location.href="#/login"
		}
	}

	render(){
		var _this=this;
		return(
			<div>
				<Router>
					<div>
						 {/* <header class="header">
							 <input type="text" placeholder="商品名称/助记码/生产企业"/> 
						</header>  */}
						<section class="section">
						<Switch>
							<Route path="/home" component={Home}></Route>
							<Route path="/classify" component={Classify}></Route>
							<Route path="/cart" component={Cart}></Route>
							<Route path="/mycenter" component={Mycenter}></Route>
							<Route path="/news" component={News}></Route>
							<Route path="/setput" component={Setput}></Route>
							<Route path="/login" component={Login}></Route>
							<Route path="/register" component={Register}></Route>
							<Route path="/detail/:id" component={Detail}></Route>

							
							<Route path="/productlist" component={Productlist}></Route>
							
							<Redirect to="/home"/>
						</Switch>
						</section>
						<footer class="footer">
						<NavLink to="./home"><p class="iconfont icon-ziyuan"></p><span>首页</span></NavLink>
						<NavLink to="./classify"><p class="iconfont icon-xinwenzixun"></p><span>分类</span></NavLink>
						<NavLink to="./cart"><p class="iconfont icon-gouwuche"></p><span>购物车</span></NavLink>
						<a onClick={this.wode.bind(this)}><p class="iconfont icon-wode"></p><span>我的</span></a>
					

						</footer>
					</div>	
				</Router>	
			</div>
		)
	}
}

export default Demo;